package com.mioto.ld.module.statistics;

import cn.hutool.core.util.StrUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @author mioto-qinxj
 * @date 2024/6/17
 * @desc
 */
public class StatisticsUtil {

    public static List<? extends StatisticsPO> reBuild(List<? extends StatisticsPO> statisticsPOS, StatisticsPO[] array, int index){
        List<StatisticsPO> newList = new ArrayList<>(index);
        String str;
        int i = 0;
        for (StatisticsPO statisticsPO : statisticsPOS) {
            str = statisticsPO.getTime();
            while (true) {
                if (newList.size() == index){
                    break;
                }
                if (StrUtil.equals(str, array[i].getTime())) {
                    newList.add(statisticsPO);
                    i++;
                    break;
                } else {
                    newList.add(array[i++]);
                }
            }
        }

        if (newList.size() < index){
            for (;i < index;){
                newList.add(array[i++]);
            }
        }
        return newList;
    }
}
